import http from '@/router/axios.js';

/**
 * @description 管理员模块接口
 */
//管理员获取用户列表
export const adminGetUserList = () => http.get('/admin/getUserList');
//管理员删除用户
export const adminDeleteUser = (id) => http.delete(`/admin/deleteUser?id=${id}`);
//管理员拉黑用户
export const adminBlockUser = (id) => http.put(`/admin/blockUser?id=${id}`);
//管理员解除拉黑
export const adminUnblockUser = (id) => http.put(`/admin/unblockUser?id=${id}`);
//管理员冻结用户
export const adminFreezeUser = (id) => http.put(`/admin/freezeUser?id=${id}`);
//管理员解冻用户
export const adminUnfreezeUser = (id) => http.put(`/admin/unfreezeUser?id=${id}`);
//管理员添加商品类型
export const adminAddProductType = (name) => http.post(`/admin/addProductType?name=${name}`);
//管理员获取商品类型列表
export const adminGetProductTypeList = () => http.get('/admin/getProductTypeList');
//管理员删除商品类型
export const adminDeleteProductType = (id) => http.delete(`/admin/deleteProductType?id=${id}`);
//管理员获取所有商铺的分类
export const adminGetAllShopGenres = () => http.get('/admin/getAllShopGenres');
//管理员根据类型获取商品列表
export const adminGetGoodsListByGenre = (value) => http.get(`/admin/getGoodsListByGenre?value=${value}`);
//管理员搜索商品
export const adminSearchGoods = (input) => http.get(`/admin/searchGoods?input=${input}`);
//管理员搜索商品名称
export const adminSearchGoodsByName = (name) => http.get(`/admin/searchGoodsByName?name=${name}`);
//管理员商品列表
export const adminGoodsLists = () => http.get('/admin/goodsList');
//管理员添加商品
export const adminAddGoods = (data) => http.post('/admin/addGoods', data);
//管理员修改商品
export const adminEditGoods = (data) => http.put('/admin/editGoods', data);
//管理员删除商品
export const adminDeleteGoods = (id) => http.delete(`/admin/deleteGoods?id=${id}`);
//管理员下架商品
export const adminSoldOutGoods = (id) => http.put(`/admin/soldOutGoods?id=${id}`);
//管理员上架商品
export const adminPutOnShelfGoods = (id) => http.put(`/admin/putOnShelfGoods?id=${id}`);
//管理员获取管理员列表
export const adminGetAdminList = () => http.get('/admin/getAdminList');
//管理员添加管理员
export const adminAddAdmin = (data) => http.post('/admin/addAdmin', data);
//管理员修改管理员
export const adminEditAdmin = (data) => http.put('/admin/editAdmin', data);
//管理员删除管理员
export const adminDeleteAdmin = (id) => http.delete(`/admin/deleteAdmin?id=${id}`);
//管理员禁用管理员
export const adminDisableAdmin = (id) => http.put(`/admin/disableAdmin?id=${id}`);
//管理员解禁管理员
export const adminUnDisableAdmin = (id) => http.put(`/admin/unDisableAdmin?id=${id}`);
//管理员登录
export const adminLogin = (data) => http.post('/admin/login', data);
//管理员注册
export const adminRegister = (data) => http.post('/admin/register', data);
//获取所有订单列表
export const getAllOrders = () => http.get('/order/list');
// 根据订单状态查询订单列表
export const getAllOrderByStatus = (status) => http.get(`/order/status/${status}`);


/**
 * @description 用户模块接口
 */
// 用户登录
export const loginUser = data => http.post('/user/login', data);
// 用户注册
export const registerUser = data => http.post('/user/register', data);
// 用户发送验证码
export const sendCode = (phone) => http.post(`/user/sendCode?phone=${phone}`);
// 手机号登录
export const loginByPhone = (phone, code, last_login_ip) => http.post(`/user/loginByPhone?phone=${phone}&code=${code}&last_login_ip=${last_login_ip}`);
// 用户获取个人信息
export const getUserInfo = (userId) => http.get(`/user/info/${userId}`);
// 用户修改个人信息
export const updateUserInfo = (data) => http.put(`/user/info`, data);
// 获取用户地址列表
export const getUserAddresses = (userId) => http.get(`/user/${userId}/addresses`);
// 添加地址
export const addAddress = (userId, data) => http.post(`/user/${userId}/addresses`, data);
// 修改地址
export const updateUserAddress = (userId, addressId, data) => http.put(`/user/${userId}/addresses/${addressId}`, data);
// 删除地址
export const deleteAddress = (addressId) => http.delete(`/user/addresses/${addressId}`);


/**
 * @description 商品模块接口
 */
// 商品列表
export const goodsLists = (page, size) => http.get(`/index/goodsList?page=${page}&size=${size}`);
//热销商品
export const hottestGoods = () => http.get('/index/hottestGoods');
//获取所有商铺的分类
export const getAllShopGenres = () => http.get('/index/getAllShopGenres');
//根据类型获取商品列表
export const getGoodsListByGenre = (value, page, size) => http.get(`/index/getGoodsListByGenre?value=${value}&page=${page}&size=${size}`);
//搜索商品
export const searchGoods = (input, page, size) => http.get(`/index/searchGoods?input=${input}&page=${page}&size=${size}`);
//搜索商品
export const searchGoodsByName = (name) => http.get(`/index/searchGoodsByName?name=${name}`);
//获取商品详情
export const fetchProductData = (id) => http.get(`/index/fetchProductData?id=${id}`);


/**
 * @description 订单发票模块接口
 */
// 创建订单
export const createOrder = (order) => http.post(`/order/create`, order);
//根据用户ID查询订单列表
export const getOrderByUserId = (user_id) => http.get(`/order/list/${user_id}`);
// 根据订单编号查询订单详情
export const getOrderByNo = (no) => http.get(`/order/no/${no}`);
// 删除订单方法（标记为已删除）
export const deleteOrder = (order_id) => http.delete(`/order/delete/${order_id}`);
//取消订单
export const cancelOrder = (order_id, status) => http.put(`/order/cancel/${order_id}/${status}`);
// 更新发票
export const updateInvoice = (invoice) => http.put(`/invoice/updateInvoice`, invoice);
// 根据订单状态查询订单列表
export const getOrderByStatus = (user_id, status) => http.get(`/order/${user_id}/status/${status}`);
// 更新订单地址方法
export const updateAddress = (address) => http.put(`/order/updateAddress`, address);
// 订单支付成功后更新订单支付时间
export const updatePayTime = (order_id) => http.put(`/order/updatePayTime?no=${order_id}`);
// 订单发货后更新订单发货时间
export const updateOrderSendTime = (order_id) => http.put(`/order/updateSendTime?order_id=${order_id}`);
// 订单完成后更新订单完成时间
export const updateOrderCompleteTime = (order_id) => http.put(`/order/updateCompleteTime?order_id=${order_id}`);
// 支付宝支付接口
export const alipay = (orderNo,subject) => http.post(`/alipay/pay?orderNo=${orderNo}&subject=${subject}`);


/**
 * @description 购物车模块接口
 */
//查看购物车
export const selectCartByUserId = (userId) => http.get(`/car/selectCartByUserId?userId=${userId}`);
//添加商品到购物车
export const insertShopCart = (data) => http.post(`/car/insertShopCart`, data);
// 修改购物车商品项数量
export const updateCartItemNum = (id, num) => http.put(`/car/updateCartItemNum?id=${id}&num=${num}`);
// 删除购物车商品项
export const deleteCartItem = (userId, goodItemId) => http.delete(`/car/deleteCartItem?userId=${userId}&goodItemId=${goodItemId}`);
// 清空购物车
export const clearCarts = (userId) => http.delete(`/car/clearCart?userId=${userId}`);


